/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package wso.bus;

import wso.dao.UserDao;
import wso.dto.WsoUser;

/**
 *
 * @author Violet_Ink
 */
public class UserBusImpl implements UserBus{

    private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public WsoUser checkLogin(String username, String password) {

        WsoUser user = userDao.getUser(username);
        boolean valid = false;
        if (user != null) {
            if (password.equals(user.getPassword())) {
                valid = true;
            }
        }
        if (valid) {
            return user;
        } else {
            return null;
        }
    }

    public void saveUser(WsoUser user) {
        userDao.saveOrUpdateUser(user);
    }

    public WsoUser[] getAllUser() {
        return userDao.getAllUser();
    }

    public WsoUser getUser(String username) {
        return userDao.getUser(username);
    }

    public WsoUser[] getUserbyRole(String roleid) {
        return userDao.getUserbyRole(roleid);
    }
    
}
